<template>
	<view class="page">
		<view class="tabbox">
			<view v-for="(item, i) in toplist" :key="i" class="tab" @click="topChange(item.id)">
				<view :class="topSign==item.id ? 'active' : ''">
					{{item.name}}
				</view>
				<view :class="topSign==item.id ? 'underline' : ''"></view>
			</view>
		</view>
		<view style="padding: 30rpx;">
			<view class="couponlist">
				<view  class="couponbox" v-for="(item,index) in list" :key="index">
					<view  :class="topSign==1? 'coupon notuse' : 'coupon used'" >
						<view class="coupon-left">
							<view class="price"> {{item.discountPrice || 0}}</view>
							<view class="priceuse"> 满{{item.usePrice}}元可用</view>
						</view>
						<view class="coupon-right">
							<view class="coupontitle"> {{item.name | truncate}}</view>
							<view class="coupontime"> {{item.validEndTime | formatDate}}到期</view>
							<view class="couponbar" @click="showdes(item,index)">
								使用说明 <u-icon name="arrow-right" size="12"></u-icon>
							</view>
						</view>
						<view class="btn" @click="btnBack(item)" v-if="topSign==1"> 去使用 </view>
						<view class="btn" style="background-color: #AAAAAA;" v-if="topSign==2"> 已使用 </view>
						<view class="btn" style="background-color: #AAAAAA;" v-if="topSign==3"> 已过期 </view>
					</view>
					<view class="descript" v-if="item.showDescript">
						<view v-if="item.type==0">
							1.仅限于{{item.descCoupon || '该'}}服务可用 
						</view>
						<view v-else-if="item.type==3">
							1.仅限于服务人员{{item.descStaffUser}}可用 
						</view>
						<view v-else>
							1.仅限于该服务人员可用 
						</view>
						<view>
							2.{{item.descCoupon}}可用
						</view>
						<view>
							3.{{item.validEndTime | formatDate('YYYY-MM-DD')}}到期，过期无效
						</view>
					</view>
				</view>
				
				<u-empty mode="coupon" v-if="list.length==0" marginTop="200" text="暂无优惠券">
				</u-empty>
			</view>
		</view>
		<woodsShareToast ref="woodsShareToast" />
	</view>
</template>

<script>
	import woodsCoupon from "@/components/woods-coupon.vue"
	import woodsShareToast from "@/components/woods-share-toast.vue"
	import {
		mapState,
		mapActions
	} from "vuex";
	import pageing from "@/mixins/pageing.js"
	import {
		couponListAPI
	} from "@/api/user.js"
	export default {
		mixins: [pageing],
		components: {
			woodsCoupon,
			woodsShareToast
		},
		data() {
			return {
				toplist: [{
					id: 1,
					name: "未使用"
				}, {
					id: 2,
					name: "已使用"
				}, {
					id: 3,
					name: "已过期"
				}],
				topSign: 1,
				list: [],
				type:''
			}
		},
		computed: {
			...mapState("select", ["city"]),
		},
		onLoad(option) {
			if(option.type){
				this.type=option.type
			}
			this.getlist()

		},

		methods: {
			showdes(item,index){
				this.list[index].showDescript=!this.list[index].showDescript
				this.$forceUpdate()
				// this.$set(this.list,)
			},
			getlist() {
				couponListAPI({
					"pageNo": this.pageNo,
					"pageSize": this.pageSize,
					"status": this.topSign,
					type:this.type
				}).then(res => {
					this.total = res.total
					this.list = this.list.concat(res.list.map(item=>{
						return {
							...item,
							showDescript:false
						}
					}));

				})
			},
			topChange(n) {
				this.topSign = n
				this.page=1
				this.list=[]
				this.getlist()
			},
			btnBack(item) {
				if(item.type==0){
					uni.switchTab({
						url:'/pages/appointment/appointment'
					})
				}else if(item.type=="1" || item.type=="3"){
					uni.redirectTo({
						url:'/pages/appointment/waiterInfo?id='+item.productScopeValues[0]
					})
					
				}else if(item.type=="2"){
					uni.redirectTo({
						url:'/pages/appointment/storeInfo?id='+item.productScopeValues[0]
					})
				}
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background: #F8F8F8;
		min-height: 100vh;
		padding-top: 80rpx;
		.tabbox {
			position: fixed;
			top: 0px;
			left: 0;
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 0 30rpx;
			background-color: #fff;
			z-index: 99;
			// height: 100rpx;
			border-bottom: 1px solid #eef0f4;
			width: 100%;

			.tab {
				padding: 20rpx;
				position: relative;

				line-height: 40rpx;
				color: #666;
				text-align: center;

			}

			.active {
				font-weight: bold;
				color: #333;
				font-size: 35rpx;

			}

			.underline {
				position: absolute;
				bottom: 0;
				left: 30%;
				width: 40%;
				height: 6rpx;
				background: $uni-color-primary;
				border-radius: 1px;
			}

		}
		 
		.used{
			background: url('https://jiejinda.oss-cn-beijing.aliyuncs.com/af4947f41a30bfa0bf9292e91e2c9b90a53ecf98589b249aa4890ef8f2d3eed2.png') 0 0 no-repeat;
		}
		.notuse{
			background: url('https://jiejinda.oss-cn-beijing.aliyuncs.com/bc23b3dec3aff55f7c83c6620effa30067bb5c4cd48a2e0ce7c8085687548b25.png') 0 0 no-repeat;
			
		}
		.coupon {
			 
			background-size: cover;
			height: 180rpx;
			width: 100%;
			display: flex;
			position: relative;
			border-radius: 20rpx;
			margin-top: 20rpx;

			.coupon-left {
				width: 32%;

				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.price {
					font-weight: bold;
					font-size: 72rpx;
					color: #FFFFFF;
					line-height: 40rpx;

				}

				.priceuse {
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 15rpx;
					line-height: 40rpx;
				}

			}

			.coupon-right {
				width: 55%;

				.coupontitle {
					font-weight: bold;
					font-size: 30rpx;
					color: #333333;
					text-align: left;
					margin-left: 10rpx;
					line-height: 60rpx;
				}

				.coupontime {
					font-size: 24rpx;
					color: #999999;
					line-height: 58rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
					margin-left: 18rpx;
				}

				.couponbar {
					font-size: 24rpx;
					display: flex;
					color: #999999;
					line-height: 58rpx;
					margin-left: 12rpx;
				}
			}

			.btn {
				position: absolute;
				right: 12rpx;
				top: 60rpx;
				background: #277EEF;
				border-radius: 34rpx;

				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				padding: 10rpx 25rpx;
			}
		}

		.descript {
			background-color: #F0F0F0;
			font-size: 20rpx;
			color: #666;
			padding: 16rpx 24rpx;
			border-radius: 0 0 20rpx 20rpx;
			line-height: 40rpx;
		}

	}
</style>